package com.lmmob.autotest.uitest.api;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class APIFactory {
    private ClassPathXmlApplicationContext context;

    public APIFactory(String config) {
        context = new ClassPathXmlApplicationContext(config);
    }

    public <T extends BaseAPI> T getAPI(Class<T> apiClass) {
        BaseAPI api = null;
        try {
            api = apiClass.newInstance();
        } catch (InstantiationException e) {

        } catch (IllegalAccessException e) {
        }
        Object actualAPI = context.getBean(api.getAPIClass());
        api.setActualAPI(actualAPI);
        return (T) api;
    }
}
